package com.gnerv.battle.boot.module.base.service.impl;

import com.gnerv.battle.boot.module.base.model.bo.RoleDatePermissionBO;
import com.gnerv.battle.boot.module.base.model.entity.RoleDataPermission;
import com.gnerv.battle.boot.module.base.repository.mapper.RoleDataPermissionMapper;
import com.gnerv.battle.boot.module.base.service.CurrentAccountService;
import com.gnerv.battle.boot.module.base.service.RoleDataPermissionService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class RoleDataPermissionServiceImpl implements RoleDataPermissionService {

    private final CurrentAccountService currentAccountService;
    private final RoleDataPermissionMapper roleDataPermissionMapper;

    @Override
    public boolean insert(RoleDatePermissionBO roleDatePermissionBO) {
        RoleDataPermission roleDataPermission = roleDatePermissionBO.toCreateRoleDataPermission();
        roleDataPermission.setCreator(currentAccountService.accountUkId());
        roleDataPermissionMapper.insert(roleDataPermission);
        return true;
    }

    @Override
    public boolean deleteByRoleUkId(String roleUkId) {
        roleDataPermissionMapper.deleteByRoleUkId(roleUkId);
        return true;
    }

    @Override
    public boolean updateByRoleUkId(RoleDatePermissionBO roleDatePermissionBO) {
        roleDataPermissionMapper.updateByRoleUkId(roleDatePermissionBO.toUpdateRoleDataPermission());
        return true;
    }

    @Override
    public RoleDataPermission selectByRoleUkId(String roleUkId) {
        return roleDataPermissionMapper.selectByRoleUkId(roleUkId);
    }
}
